package com.springboot.erp.controller;

import com.springboot.erp.common.CommonResult;
import com.springboot.erp.entity.ExpenseDTO;
import com.springboot.erp.entity.JshAccountHead;
import com.springboot.erp.service.ExpenseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/expense")
@Slf4j
public class ExpenseController {

    @Resource ExpenseService expenseService;
    @RequestMapping("/{id}")
    public CommonResult<ExpenseDTO> selectExpenseById(@PathVariable Long id) {
        return CommonResult.success(expenseService.selectExpenseById(id));
    }

    @GetMapping("/listExpenses")
    public CommonResult<List<JshAccountHead>> listExpenses(Long organId, String status, Date startDate, Date endDate) {
        List<JshAccountHead> expenses = expenseService.listExpenses(organId, status, startDate, endDate);
        return CommonResult.success(expenses);
    }

    @PostMapping
    public CommonResult<Void> addOne(@RequestBody JshAccountHead jshAccountHead) {
        expenseService.addOne(jshAccountHead);
        return new CommonResult( 0, "success", null);
    }
    @PutMapping
    public CommonResult<Void> updateOne(@RequestBody JshAccountHead jshAccountHead) {
        expenseService.updateOne(jshAccountHead);
        return new CommonResult( 0, "success", null);
    }
    @DeleteMapping("/{id}")
    public CommonResult<Void> deleteOne(@PathVariable Integer id) {
        expenseService.deleteOne(id);
        return new CommonResult( 0, "success", null);
    }
}
